package cn.dnui_xcz826.dnuifood_16110100826.fragments;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.dnui_xcz826.dnuifood_16110100826.R;


public abstract class BaseFragment extends Fragment {
    private SharedPreferences sp;
    protected FragmentManager childManager;
    protected Context context;
    protected View view=null;
    protected int layout_file=0;

    void setLayout_file(int layout_file)
    {
        this.layout_file=layout_file;
    }
    int getLayout_file()
    {
        return this.layout_file;
    }

    public BaseFragment() {
        context=getActivity();
    }
    public String getUser_id(){
        sp=getActivity().getSharedPreferences("userInfo",Context.MODE_PRIVATE);
        return sp.getString("user_id","");
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       view=inflater.inflate(getLayout_file(),container,false);
        childManager=getChildFragmentManager();
        return view;

    }
    public void onAttach(Context context){
        super.onAttach(context);
        this.context=context;
    }

    abstract void initViews();
    abstract void initEvents();
    abstract void initData();

//    public static BaseFragment newInstance(String text){
//        Bundle bundle = new Bundle();
//        bundle.putString("text",text);
//        BaseFragment baseFragment = new BaseFragment();
//        baseFragment.setArguments(bundle);
//        return  baseFragment;
//    }

}
